package com.service;

import com.thread.ServerConnectClientThread;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * 1. 该类用于管理和客户端通信的服务器端线程
 */
public class ManageClientThreads {
    // key - 用户id,
    private static Map<String, ServerConnectClientThread> hm = new HashMap();

    public static Map<String, ServerConnectClientThread> getHm() {
        return hm;
    }

    public static void setHm(Map<String, ServerConnectClientThread> hm) {
        ManageClientThreads.hm = hm;
    }

    public static void  addServerConnectClientThread(String userId, ServerConnectClientThread thread){
        hm.put(userId,thread);
    }


    public static ServerConnectClientThread  getServerConnectClientThread(String userId){
        return  hm.get(userId);
    }

    /**
     * 1. 从集合中删除某个线程对象
     * @param userId
     * @return
     */
    public static void  remove(String userId){
          hm.remove(userId);
    }


    public static String getOnlineUser(){
        Iterator<String> iterator = hm.keySet().iterator();
        String user="";
        while (iterator.hasNext()){
            user+=iterator.next().toString()+" ";
        }
        return user;
    }
}

